package com.googlecode.wicketcharts.highcharts.gson;

import java.awt.Color;
import java.lang.reflect.Type;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

/**
 * Serializes AWT {@link Color} objects to JSON.
 * 
 * @author Tom
 * 
 */
public class GsonColorSerializer implements JsonSerializer<Color> {

	@Override
	public JsonElement serialize(Color src, Type typeOfSrc, JsonSerializationContext context) {
		return new JsonPrimitive(Integer.toHexString(src.getRGB()).replaceFirst("ff", "#"));
	}

}
